﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Pout_Porri.Objects.Interface;
using Pout_Porri.Utils;

namespace Pout_Porri.Objects
{
    class Helmet : Enemy, ICollisionBoundaries
    {
        private Animation helmetThrowing;
        private double elapsedTime;
        private float frameRate;

        public Helmet(Texture2D image, Vector2 position, Vector2 velocity) : base(image, position, velocity)
        {
            this.texture = image;
            this.Mass = 0.5f;
            setGrounded(true);
            this.frameRate = 10;
            this.DefaultVelocityX = velocity.X;
        }

        public override void configAnimations()
        {
            helmetThrowing = new Animation("helmetthrowing", new Vector2(84, 84), 200, 4, 2, 7, Axis.X);
            this.addAnimation(helmetThrowing);

            this.spriteTexture = new Texture2D(Game1.graphics.GraphicsDevice, 84, 84);

            this.setCurrentAnimation("helmetthrowing");
            currentState = EnemyStates.running;
        }

        public override void update(GameTime gameTime)
        {
            checkMatrixCollisionInY();

            IA(MyLevel.getPlayer());
               
            if (currentState == EnemyStates.running)
            {
                this.setCurrentAnimation("helmetthrowing");
                
            }
            
            Walk(gameTime);

            currentAnimationRect = this.AnimationRect(this.getCurrentAnimation());

            collisionBoundaries();

            base.update(gameTime);
        }

        public void Walk(GameTime gameTime)
        {
            if (gameTime.TotalGameTime.TotalMilliseconds > elapsedTime + frameRate)
            {
                elapsedTime = gameTime.TotalGameTime.TotalMilliseconds;

                applyMovement(gameTime);
            }
            
            
        }

        

        public void IA(PhysicsGameEntity player)
        { 
            Game1.window.Title = "" + this.position.X + this.direction.X;

            this.direction.X = -1;
        }


        private bool isBoundaryLeft;
        public bool IsBoundaryLeft
        {
            get
            {
                return isBoundaryLeft;
            }
            set
            {
                isBoundaryLeft = value;
            }
        }

        public bool IsBoundaryRight
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }


        public void collisionBoundaries()
        {
            if (this.position.X < Game1.graphics.GraphicsDevice.Viewport.Bounds.Left - 20)
            {
                IsBoundaryLeft = true;
                this.position.X = Game1.graphics.GraphicsDevice.Viewport.Bounds.Right - 20;
                //this.setVisible(false);
                Game1.window.Title = "" + this.isVisible();
            }
        }

        

        public bool collisionLadder()
        {
            throw new NotImplementedException();
        }

        public bool collisionHole()
        {
            throw new NotImplementedException();
        }
    }
}
